﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FlowBasis.Web.Mvc;

namespace FlowBasisSampleSite.Areas.Developers.Controllers
{

    [UserAuthorize(RequiredPermissions = new[] { FlowBasis.Security.BasicPermissions.SiteAdmin })]
    public class PostRpcTestController : Controller
    {
        
        public ActionResult Index()
        {
            return View();
        }


        [PostRpc]
        public ActionResult TestAdd(int x, int y)
        {
            int result = x + y;

            return new PostRpcResult(result);
        }

        [PostRpc]
        public ActionResult TestThrowException(string message)
        {
            throw new Exception(message);
        }

        [PostRpc]
        [UserAuthorize(RequiredPermissions = new[] { "SomePermissionThatDoesNotExistSoUserWillNotHaveIt" })]
        public ActionResult TestPermissionDenied()
        {
            throw new Exception("This should not be reached.");
        }

        [PostRpc]
        public ActionResult TestModelBinding(TestModel testModel)
        {
            return new PostRpcResult(new TestResult() { Description = testModel.SomeValue + " - " + testModel.TestEnum });
        }

        public class TestModel
        {
            public string SomeValue { get; set; }
            public TestEnum TestEnum { get; set; }
        }

        public class TestResult
        {
            public string Description { get; set; }
        }

        public enum TestEnum
        {
            One,
            Two,
            Three
        }
    }
}
